//TODO: GET RID OF THIS IDIOTIC CLASS

/// <summary>** BEGIN LICENSE BLOCK *****
/// Version: LGPL 3
/// 
/// Copyright 2008 David Cumps <david@cumps.be>
/// 
/// This file is part of ArmoryLib2.
///
/// ArmoryLib is free software: you can redistribute it and/or modify
/// it under the terms of the GNU Lesser General Public License as published by
/// the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// ArmoryLib is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/// GNU Lesser General Public License for more details.
///
/// You should have received a copy of the GNU Lesser General Public License
/// along with ArmoryLib2.  If not, see <http://www.gnu.org/licenses/>.
/// **** END LICENSE BLOCK ****
/// </summary>
using System.Globalization;
using System.Web;
using System.Xml;
using ArmoryLib2.Character;

namespace ArmoryLib2
{
    internal class Util
    {
        internal static NumberFormatInfo NumberFormatter
        {
            get
            {
                NumberFormatInfo provider = new NumberFormatInfo();
                provider.NumberDecimalSeparator = ".";
                provider.NumberGroupSeparator = ",";
                provider.NumberGroupSizes = new int[] { 3 };
                return provider;
            }
        }
        public static XmlNode LoadDetailNode(Armory armory, CharacterDetail detail, string realmName, string characterName)
        {
            string searchString = string.Empty;
            switch (detail)
            {
                case CharacterDetail.Basic:
                case CharacterDetail.CharacterSheet:
                    // http://eu.wowarmory.com/character-sheet.xml?r=Sporeggar&n=Zoing
                    searchString = string.Format("character-sheet.xml?r={0}&n={1}",
                                                 HttpUtility.UrlEncode(realmName),
                                                 HttpUtility.UrlEncode(characterName));
                    break;
                case CharacterDetail.Reputation:
                    // http://eu.wowarmory.com/character-reputation.xml?r=Sporeggar&n=Zoing
                    searchString = string.Format("character-reputation.xml?r={0}&n={1}",
                                                 HttpUtility.UrlEncode(realmName),
                                                 HttpUtility.UrlEncode(characterName));
                    break;
                case CharacterDetail.Skills:
                    // http://eu.wowarmory.com/character-skills.xml?r=Sporeggar&n=Zoing
                    searchString = string.Format("character-skills.xml?r={0}&n={1}",
                                                 HttpUtility.UrlEncode(realmName),
                                                 HttpUtility.UrlEncode(characterName));
                    break;
                case CharacterDetail.Talents:
                    // http://eu.wowarmory.com/character-talents.xml?r=Sporeggar&n=Zoing
                    searchString = string.Format("character-talents.xml?r={0}&n={1}",
                                                 HttpUtility.UrlEncode(realmName),
                                                 HttpUtility.UrlEncode(characterName));
                    break;
                case CharacterDetail.Arena:
                    // http://eu.wowarmory.com/character-arenateams.xml?r=Sporeggar&n=Zoing
                    searchString = string.Format("character-arenateams.xml?r={0}&n={1}",
                                                 HttpUtility.UrlEncode(realmName),
                                                 HttpUtility.UrlEncode(characterName));
                    break;
            }

            if (searchString != string.Empty)
            {
                XmlDocument searchResults = armory.Request(searchString);
                XmlNode characterDetails = searchResults.SelectSingleNode("/page/characterInfo");
                return characterDetails;
            }
            else
            {
                return null;
            }
        }

    }

    internal static class UtilExtensions
    {
        internal static bool Between(int value, int min, int max)
        {
            return value >= min && value <= max;
        }
    }
}
